package cbbx_sm.evaluation;

import java.io.IOException;
import java.util.List;
import java.util.Vector;

import cbbx_sm.decision_maker.DecisionMakerFactory;
import cbbx_sm.decision_maker.IDecisionMaker;
import cbbx_sm.parser.CameraData;
import cbbx_sm.parser.Parser;
import cbbx_sm.probabilistic_model.Cluster;
import cbbx_sm.probabilistic_model.IPredictor;
import cbbx_sm.probabilistic_model.NoisyOrPredictor;
import cbbx_sm.probabilistic_model.ProbabilisticModel;
import cbbx_sm.probabilistic_model.SystemShortTermMemory;
import cbbx_sm.simulation.Scheduler;
import cbbx_sm.utils.Utility;

public class AlfaBetaTest16_17_18 {
	public static void main(String[] args) throws IOException, InterruptedException{
//		CameraData data14 = Parser.parseFile("data/cameraData/2009052814.txt", "cam14");
		CameraData data16 = Parser.parseFile("data/cameraData/2009052816.txt", "cam16");
//		CameraData data15 = Parser.parseFile("data/cameraData/2009052815.txt", "cam15");
//		CameraData data13 = Parser.parseFile("data/cameraData/2009052813.txt", "cam13");
		CameraData data17 = Parser.parseFile("data/cameraData/2009052817.txt", "cam17");
		CameraData data18 = Parser.parseFile("data/cameraData/2009052818.txt", "cam18");
		
		
//		data14.setImageFile("data/images/14.jpg");
		data16.setImageFile("data/images/16.jpg");
//		data15.setImageFile("data/images/15.jpg");
//		data13.setImageFile("data/images/13.jpg");
		data17.setImageFile("data/images/17.jpg");
		data18.setImageFile("data/images/18.jpg");
		
//		List<Cluster> clusters14 = Utility.getClusters("data/clusterData/Kruskal_150.0_2009052814.txt", "cam14", data14);;
		List<Cluster> clusters16 = Utility.getClusters("data/clusterData/Kruskal_150.0_2009052816.txt", "cam16", data16);;
//		List<Cluster> clusters13 = Utility.getClusters("data/clusterData/Kruskal_150.0_2009052813.txt", "cam13", data13);
//		List<Cluster> clusters15 = Utility.getClusters("data/clusterData/Kruskal_150.0_2009052815.txt", "cam15", data15);
		List<Cluster> clusters17 = Utility.getClusters("data/clusterData/Kruskal_150.0_2009052817.txt", "cam17", data17);
		List<Cluster> clusters18 = Utility.getClusters("data/clusterData/Kruskal_150.0_2009052818.txt", "cam18", data18);;
		
		List<Cluster> fusedClusters = new Vector<Cluster>();
		
//		fusedClusters.addAll(clusters14);
		fusedClusters.addAll(clusters16);
//		fusedClusters.addAll(clusters13);
//		fusedClusters.addAll(clusters15);
		fusedClusters.addAll(clusters17);
		fusedClusters.addAll(clusters18);
	
		List<CameraData> cameraData = new Vector<CameraData>();
//		cameraData.add(data14);
		cameraData.add(data16);
//		cameraData.add(data13);
//		cameraData.add(data15);
		cameraData.add(data17);
		cameraData.add(data18);
		
		List<List<Cluster>> clusters = new Vector<List<Cluster>>();
//		clusters.add(clusters14);
		clusters.add(clusters16);
//		clusters.add(clusters15);
//		clusters.add(clusters13);
		clusters.add(clusters17);
		clusters.add(clusters18);
		
		System.out.println("NUMBER OF BBOX TO CATCH: " + (data16.getNumberOfFrameWithBoundingBoxes() +
							data17.getNumberOfFrameWithBoundingBoxes() + data18.getNumberOfFrameWithBoundingBoxes()));
		System.out.println("Starting calculating probs...");
//		ProbabilisticModel probModel = new ProbabilisticModel();
//		probModel.computeProbabilities(cameraData, fusedClusters, (18 - 13) * 60 * 60);
//		ProbabilisticModel.writeDown(probModel, "16-17-18_150Clust.ser");
//		ProbabilisticModel probModel1 = ProbabilisticModel.readUp("14-16_150Clust.ser");
		ProbabilisticModel probModel = ProbabilisticModel.readUp("old_13-14-15-16-17-18_150Clust.ser");
//		ProbabilisticModel probModel = ProbabilisticModel.readUp("16-17-18_150Clust.ser")
		System.out.println("Probability computed:");
//		System.out.println(probModel);
//		System.out.println();
		
		SystemShortTermMemory memory;
		IPredictor predictor;
		IDecisionMaker decisionMaker;
		Scheduler scheduler;
		
		for (double alfa = 0.05; alfa < 1.0; alfa += 0.05)
			for (double beta = 0.0; beta < 1.0 - alfa; beta += 0.05)
				for (double cut_off = 0.0; cut_off < alfa; cut_off += (alfa / 10)){
					memory = new SystemShortTermMemory(5);
					predictor = new NoisyOrPredictor(memory, probModel, 15, fusedClusters, true);
					decisionMaker = DecisionMakerFactory.getAlfaBetaDecisionMaker(alfa, beta, cut_off);
					scheduler = new Scheduler(cameraData, fusedClusters, clusters, probModel);
					scheduler.setDecisionMaker(decisionMaker);
					scheduler.setMemory(memory);
					scheduler.setPredictor(predictor);
//					scheduler.start();
//					scheduler.join();
					System.gc();
				}
	}
}
